<template>
  <!--  <el-form ref="contentForm" label-width="70px" :model="form">-->
  <!--    <el-form-item label="工作内容" prop="content">-->
  <!--      <el-input type="textarea" v-model="form.content" />-->
  <!--    </el-form-item>-->
  <!--    <el-form-item>-->
  <!--      <el-button type="primary" @click="confirm()">确认</el-button>-->
  <!--    </el-form-item>-->
  <!--    <el-form-item>-->
  <!--      <el-button type="primary" @click="updateEndTime()">任务完成</el-button>-->
  <!--    </el-form-item>-->
  <!--  </el-form>-->
  <div style="margin: 10px 10px 0">
    <el-input
        v-model="form.content"
        :rows="4"
        type="textarea"
        placeholder="Please input"
    />
    <el-button style="display: flex;margin-left: auto;margin-top:10px" type="primary" @click="confirm">确认</el-button>
  </div>
  <div  v-for="item in (form.contentList)" :key="item.id">
    <el-card style="margin: 10px;">
    {{item.content}}
      <el-button style="display: flex;margin-left: auto;margin-top:10px" type="primary" @click="updateEndTime(item)">任务完成</el-button>
    </el-card>

  </div >





</template>

<script lang="ts">
import {defineComponent, getCurrentInstance, computed, reactive, ref, watch, onMounted,nextTick } from "vue";
import { useStore } from "vuex";
import mixin from "@/mixins/mixin";
import { HttpManager } from "@/api";
export default defineComponent({
  setup() {
    const store = useStore();
    const { proxy } = getCurrentInstance();
    const {checkStatus} = mixin();
    const form = reactive({
      content: "",
      contentList:[]
    });
    const userId = computed(() => store.getters.userId);

    const getContent=()=>{

      HttpManager.getContent({userId:localStorage.getItem('userId')}).then(res=>{
        const a=res as any
        a.data.forEach((item:any)=>{
          form.contentList.push(item)
        })
      })

    }

    getContent()

    async function confirm() {
      if (!checkStatus())
        return;
      let content = form.content;
      const result = (await HttpManager.addContent({userId:userId.value,content})) as ResponseBody;
      (proxy as any).$message({
        message: result.message,
        type: result.type,
      });
    }
    async function updateEndTime(data:any) {
      console.log(data)
      if (!checkStatus())
        return;
      // let content = form.content;
      const result = (await HttpManager.updateEndTime({id:data.id})) as ResponseBody;
      (proxy as any).$message({
        message: result.message,
        type: result.type,
      })
    }
    return {
      form,
      confirm,
      updateEndTime,
    };

  },
});
</script>

<style>
</style>
